package report

import (
	"github.com/gin-gonic/gin"
	"go-interview-forum/resp"
	"go-interview-forum/service/report"
	"strconv"
)

func GetAllNumber(c *gin.Context) {
	data, err := report.GetCateMasterQuantity(1)
	if err != nil {
		resp.ServerErrorResp(c, resp.SERVER_ERR, err.Error())
		return
	}

	resp.SuccessResp(c, data)
}

func GetCateSumQuantity(c *gin.Context) {
	data, err := report.GetCateSumQuantity()
	if err != nil {
		resp.ServerErrorResp(c, resp.SERVER_ERR, err.Error())
		return
	}

	resp.SuccessResp(c, data)
}

// BushReportCreate 返回分类掌握率未掌握率
func BushReportCreate(c *gin.Context) {
	value, exists := c.Get("userId")
	if !exists {
		resp.ServerErrorResp(c, resp.SERVER_ERR, "服务器错误")
		return
	}
	userId, err := strconv.Atoi(value.(string))
	if err != nil {
		resp.ServerErrorResp(c, resp.SERVER_ERR, "服务器错误")
		return
	}

	rate, err := report.GetUserMasteryRates(userId)
	if err != nil {
		resp.ServerErrorResp(c, resp.SERVER_ERR, err.Error())
		return
	}

	resp.SuccessResp(c, rate)
}
